/* Copyright  2009
   @Author
   Richard Changde Yin            e-mail yinchangde@hotmail.com

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; version 2 of the License.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

/**
 * @filename: select_result.h
 */


#ifndef __SELECT_RESULT_H__
#define __SELECT_RESULT_H__

class JOIN ;
class select_result :public Sql_alloc {
protected:
  Session *session;

  Select_Lex_Unit *unit;
public:
  select_result()
  {
    session= current_session;
  }
  /*The virtual destructor */
  virtual ~select_result() {};
  virtual int prepare(List<Item> &,Select_Lex_Unit *u)

  {
    unit= u;
    return 0;
  }
  /*
    Because of peculiarities of prepared statements protocol
    we need to know number of columns in the result set (if
    there is a result set) apart from sending columns metadata.
  */
  virtual uint32_t field_count(List<Item> &fields) const
  { return fields.elements; }

  virtual bool send_fields(List<Item> &list, uint32_t flags)=0;

  virtual bool send_data(List<Item> &items)=0;

  virtual bool initialize_tables (JOIN *)
  { return 0; }

  virtual bool send_eof()=0;

  virtual void abort() {}

  void set_session(Session *session_arg) { session= session_arg; }

  void begin_dataset() {}

  /*****************************************************************************
   ** Functions to provide a interface to select results
   *****************************************************************************/

  virtual void send_error(uint32_t errcode, const char *err)
  {
    db_message(errcode, err, MYF(0));
  }

  /*
    Cleanup instance of this class for next execution of a prepared
    statement/stored procedure.
  */
  virtual void cleanup()
  {
    /* do nothing */
  }

};

#endif /* __SELECT_RESULT_H__ */
